class Access extends DevAccess{
    Employee emp
    Area area
    Container container

    //static belongsTo = [Employee, Area, Container]

    static constraints = {

    }
    public List getList(String controller){
        switch(controller){
            case "project" :
                if(hasAdminAuth()){
                    ArrayList  list = new ArrayList()
                    def areas = container.areas

                    for(Area a : areas){
                       // println(a)
                        def temp
                        if(DBConnection.isConnectionStarted()){
                            temp = DBConnection.findProjectByArea(a)
                        }
                        else{
                            temp = Project.findAllByArea(a)
                        }

                        for( Project p : temp){
                            if(p){
                                list.add(p)
                            }
                        }
                    }
                    //println(list)
                    return list
                }
                else if(hasManagerAuth()){

                    def temp
                    if(DBConnection.isConnectionStarted()){
                        temp = DBConnection.findProjectByArea(a)
                    }
                    else{
                        temp = Project.findAllByArea(a)
                    }
                    return temp
                }
            break
        }
    }

    public Boolean checkAccess(String controller, String action, Long id){
       // if(controller.equalsIgnoreCase("area")){
            switch(action){
                case "show" :
                    println("Container: " + this.container.id)
                    def area = Area.get(id)
                    println("Incomming id: " + area.container.id)
                    if(this.role.level == 1){
                        return this.container.equals(Container.get(area.container.id))
                    }
                    if(this.role.level == 2){
                        def a = Area.get(id)
                        return (this.area.id.equals(a.id) && this.container.id.equals(a.container.id))
                    }
                    return false
                    break
                case "create" :
                    if(this.role.level == 1){
                        return true
                    }
                    else return false
                    break
                case "edit" :
                    if(this.role.level == 1){
                        def area = Area.get(id)
                        return area.container.id == this.container.id
                    }
                    if(this.role.level == 2){
                        def area = Area.get(id)
                        return (this.area.id.equals(area.id) && this.container.id.equals(area.container.id))
                    }
                    return false
                    break
                case "delete" :
                    if(this.role.level == 1){
                        return this.container.equals(Container.get(id))
                    }
                    return false
                    break
                case "save" :
                    if(this.role.level == 1){
                        return this.container.id == id
                    }
                    return false
                    break
                default : return false
                }
            }
           // else{
           //     return false
           // }
        //}
    //String toString(){"${this.emp} : ${this.role}"}
    String toString(){"${this.role}"}
}